{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ac862e48",
   "metadata": {},
   "outputs": [],
   "source": [
    "def collatz(n):\n",
    "    '''\n",
    "    Purpose: A recursive function called collatz that takes in a single positive \n",
    "    integer argument n and returns the sum of numbers in the collatz sequence from n to 1, inclusive. \n",
    "    n: A positive number\n",
    "    Return Value: An int\n",
    "    '''\n",
    "    \n",
    "    if n == 1:\n",
    "        return 1\n",
    "    if n % 2 == 1:\n",
    "        return collatz(3*n+1)+n\n",
    "    else:\n",
    "        return collatz(n//2)+n\n",
    "def is_pos_reversible(alist):\n",
    "    '''\n",
    "    Purpose: A function that takes a list of integers and tests whether the positive ints in that list could be read the same forward as backwards.\n",
    "    The positions of 0s and negative values don’t matter.\n",
    "    alist: A list\n",
    "    Return Value: Boolean value\n",
    "    '''\n",
    "    if len(alist)==0 or len(alist) == 1:\n",
    "        return True\n",
    "    if alist[0] <= 0:\n",
    "        return is_pos_reversible(alist[1:])\n",
    "    elif alist[-1] <= 0:\n",
    "        return is_pos_reversible(alist[:-1])\n",
    "    else:\n",
    "        return bool((alist[0]==alist[-1])*is_pos_reversible(alist[1:-1]))\n",
    "def all_subsets(alist):\n",
    "    '''\n",
    "    Purpose: A function that takes as a parameter a list of items and returns a list containing all subsets\n",
    "    alist: A list\n",
    "    Return Value: All the subsets of alist\n",
    "    '''\n",
    "    if alist == []:\n",
    "        return [[]]\n",
    "    return all_subsets(alist[1:]) + [[alist[0]]+i for i in all_subsets(alist[1:])]"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
